import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:im_base/public/pages/video_player/logic.dart';
import 'package:video_player/video_player.dart';

///@author:create by BZY
///Date: 2021/9/7 14:10
///Description: 视频播放页面
class VideoPlayerPage extends StatelessWidget {
  final logic = Get.put(VideoPlayerLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black54,
      body: GetBuilder<VideoPlayerLogic>(
        init: logic,
        builder: (controller) {
          return Stack(
            children: [
              GestureDetector(
                onDoubleTap: () => logic.toggleState(),
                child: Hero(
                    tag: logic.tag ?? '',
                    child: Center(
                      child: logic.controller!.value.isInitialized
                          ? AspectRatio(
                              aspectRatio: logic.controller!.value.aspectRatio,
                              child: VideoPlayer(logic.controller!),
                            )
                          : Container(),
                    )),
              ),
              Center(
                  child: GetBuilder<VideoPlayerLogic>(
                id: 'play',
                init: logic,
                builder: (controller) {
                  return logic.controller!.value.isPlaying
                      ? Container()
                      : Icon(
                          Icons.play_circle_outline_outlined,
                          color: Colors.white,
                          size: 48,
                        );
                },
              )),
              Align(
                alignment: Alignment.topLeft,
                child: Container(
                  margin: const EdgeInsets.only(top: 24),
                  child: IconButton(
                      onPressed: () => Get.back(),
                      icon: Icon(
                        Icons.arrow_back,
                        color: Colors.white,
                      )),
                ),
              )
            ],
          );
        },
      ),
    );
  }
}
